package com.xiaoyu.lanling.feature.chat.viewholder.messageclick;

import android.view.View;

import androidx.appcompat.app.AlertDialog;

import com.xiaoyu.base.app.AppContext;
import com.xiaoyu.lanling.R;
import com.xiaoyu.lanling.feature.chat.model.message.ChatMessageReceiveVideoItem;
import com.xiaoyu.lanling.feature.chat.model.message.ChatMessageSendVideoItem;
import com.xiaoyu.lanling.feature.im.provider.MessageDataProvider;
import com.xiaoyu.lanling.util.ViewTagUtil;

public class ChatMessageVideoItemClickHandler {

    public static final View.OnLongClickListener receiveVideoOnLongClickListener = v -> {
        ChatMessageReceiveVideoItem itemData = ViewTagUtil.getTag(v, ChatMessageReceiveVideoItem.class);
        if (itemData == null) {
            return false;
        }
        final CharSequence[] items = new CharSequence[]{AppContext.getString(R.string.action_delete)};
        new AlertDialog.Builder(v.getContext())
                .setItems(items, (dialog, which) -> {
                    MessageDataProvider.Companion.getInstance().deleteMessageAsync(itemData.getMessage());
                    dialog.dismiss();
                }).show();
        return true;
    };

    public static final View.OnLongClickListener sendVideoOnLongClickListener = v -> {
        ChatMessageSendVideoItem itemData = ViewTagUtil.getTag(v, ChatMessageSendVideoItem.class);
        if (itemData == null) {
            return false;
        }
        final CharSequence[] items = new CharSequence[]{AppContext.getString(R.string.action_delete)};
        new AlertDialog.Builder(v.getContext())
                .setItems(items, (dialog, which) -> {
                    MessageDataProvider.Companion.getInstance().deleteMessageAsync(itemData.getMessage());
                    dialog.dismiss();
                })
                .show();
        return true;
    };

    public static void bindReceiveVideoItemLongClickForViewAndData(View view, ChatMessageReceiveVideoItem itemData) {
        view.setOnLongClickListener(receiveVideoOnLongClickListener);
        ViewTagUtil.setViewTagForClick(view, itemData);
    }

    public static void bindSendVideoItemLongClickForViewAndData(View view, ChatMessageSendVideoItem itemData) {
        view.setOnLongClickListener(sendVideoOnLongClickListener);
        ViewTagUtil.setViewTagForClick(view, itemData);
    }
}
